﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Account : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["user"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请登录');\nlocation.href('Default.aspx');", true);
            }
            else
            {
                DbAccess db = new DbAccess();
                string uid = Session["user"].ToString();
                DataSet ds = db.GetDataSet("select account from userInfo where uid='" + uid + "'");
                lblUser.Text = uid;
                lblAccount.Text = ds.Tables[0].Rows[0][0].ToString();


            }
        }

    }
    protected void btnCharge_Click(object sender, EventArgs e)
    {
        string account = TextBox1.Text;
        try
        {
            DbAccess db = new DbAccess();
            string uid = Session["user"].ToString();
            string sql = "update userInfo set account=account+" + decimal.Parse(account) + " where uid='" + uid + "'";
            if (db.ExecuteSql(sql))
            {

                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('充值成功');\nlocation.href('Default.aspx');", true);

            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('充值失败');\nlocation.href('Default.aspx');", true);

            }
        }
        catch
        { 
        
        }

    }
   
}
